import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../view/OneRouter/Login.vue'
import Home from '../view/OneRouter/Hmoe.vue'

import GoodAside from '../view/TwoRouter/GoodsAside/GoodAside.vue'

import RunAside from '../view/TwoRouter/RunAside/RunAside.vue'

import WeCome from '../view/TwoRouter/WeCome.vue'

import GoodsList from '../view/ThreeRouter/Goods/GoodsList.vue'

// AddGoods
import SelectGoodsParams from '../view/ThreeRouter/Goods/AddGoods/SelectGoodsParams.vue'
import XieGoodsInfo from '../view/ThreeRouter/Goods/AddGoods/XieGoodsInfo.vue'
import AddGoodsOver from '../view/ThreeRouter/Goods/AddGoods/AddGoodsOver.vue'

// GoodsSortPage
import FistGoodsSort from '../view/ThreeRouter/Goods/GoodsSort/FistGoodsSort.vue'
import TwoGoodsSort from '../view/ThreeRouter/Goods/GoodsSort/TwoGoodsSort.vue'
import LastGoodsSort from '../view/ThreeRouter/Goods/GoodsSort/LastGoodsSort.vue'
import AddGoodsSort from '../view/ThreeRouter/Goods/GoodsSort/AddGoodsSort.vue'

import Runs from '../view/ThreeRouter/Runs/Runs.vue'

import TimeList from '../view/ThreeRouter/Runs/TimeList.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: Login
  },
  {
    // home主页路由
    path: '/home',
    component: Home,
    // 侧边栏路由
    children: [
      // 主页侧边栏路由
      {
        path: '/home',
        component: WeCome
      },
      // 商品侧边栏路由
      {
        path: '/goods',
        component: GoodAside,
        redirect: '/goods/goodsList',
        children: [
          {
            // 商品列表
            name: 'goodsList',
            path: '/goods/goodsList',
            component: GoodsList,
            meta: {
              keepAlive: false
            }
          },
          // 添加商品
          {
            path: '/goods/addGoods/select',
            component: SelectGoodsParams,
            meta: {
              keepAlive: true
            }
          },
          {
            path: '/goods/addGoods/xie',
            component: XieGoodsInfo,
            meta: {
              keepAlive: true
            }
          },
          {
            path: '/goods/addGoods/over',
            component: AddGoodsOver,
            meta: {
              keepAlive: true
            }
          },
          // 商品分类
          {
            path: '/goods/goodsSort/fist',
            component: FistGoodsSort,
            meta: {
              keepAlive: false
            }
          },
          {
            path: '/goods/goodsSort/two/:id',
            component: TwoGoodsSort,
            meta: {
              keepAlive: false
            },
            props: true
          },
          {
            path: '/goods/goodsSort/last/:id',
            component: LastGoodsSort,
            meta: {
              keepAlive: false
            },
            props: true
          },
          {
            path: '/goods/goodsSort/add',
            component: AddGoodsSort,
            meta: {
              keepAlive: false
            }
          }
          //
        ]
      },
      // 运营侧边栏路由
      {
        path: '/runs',
        component: RunAside,
        redirect: '/runs/miaoSha',
        children: [
          {
            path: '/runs/miaoSha',
            component: Runs
          },
          {
            path: '/runs/timeList',
            component: TimeList
          }
        ]
      },
      {
        path: '/all',
        component: WeCome
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  // console.log(to)
  // console.log(from, 'from')

  if (to.path === '/login') next()

  let ToKen = window.localStorage.getItem('token')
  console.log(ToKen)

  if (ToKen) {
    next()
  } else {
    next('/login')
  }
})

export default router
